<include file="Public:header" />
<include file="Public:left" />
<form  method="post" enctype="multipart/form-data" id="brandForm" name="brandForm">
    <section>
        <h2><strong>添加分类</strong></h2>
        <ul class="ulColumn2">
            <input type="hidden" name="id" value="{$data.id}">
            <li>
                <span class="item_name" style="width:120px;">所属菜单栏目：</span>
                <select name="nav_id" id="">
                    <volist name="nav_result" id="vo">
                        <option value="{$vo.id}" <if condition="$data.nav_id == $vo.id">selected</if>>{$vo.name}</option>
                    </volist>
                </select>
            </li>
            <li>
                <span class="item_name" style="width:120px;">分类名称：</span>
                <input type="text" class="textbox textbox_295" name="title" id="title" placeholder="分类名称..." value="{$data.name}"/>
            </li>
            <li>
                <span class="item_name" style="width:120px;"></span>
                <input type="button" class="link_btn" value="提交"/>
            </li>
        </ul>
    </section>
</form>
<!--tabStyle-->

<script type="text/javascript">
    $(document).ready(function(){
        //tab
        $(".admin_tab li a").click(function(){
            var liindex = $(".admin_tab li a").index(this);
            $(this).addClass("active").parent().siblings().find("a").removeClass("active");
            $(".admin_tab_cont").eq(liindex).fadeIn(150).siblings(".admin_tab_cont").hide();
        });

        $(".link_btn").click(function(){

            if($("#title").val()==""){
                layer.alert("分类名称不能为空!");
                return false;
            }

            var formData = new FormData();
            var title = $('input[name="title"]').val();
            var nav_id = $('select[name="nav_id"]').val();
            var id = $('input[name="id"]').val();

            formData.append('title', title);
            formData.append('nav_id', nav_id);
            formData.append('id', id);

            $.ajax({
                url:"{:url('Category/add')}",
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
                    if(result.code == '0'){
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg, {
                                    btn: ['确定']
                                },
                                function (index, item) {
                                    location.href = result.url;
                                });
                    }
                }

            });

        });

    });
</script>
</section>
</body>
</html>
